package com.chhuang.ewcrm.ctrl;

import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.control.Tab;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

/**
 * 查询报表
 * @author chhuang
 * @create 2020-10-11-15:08
 */
public class ReportController implements InitController {
    private final Logger logger = LoggerFactory.getLogger(ReportController.class);

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {

    }

    /**
     * tab动态加载数据，懒加载
     * @param event
     * @throws IOException
     */
    @FXML
    private void onSelectionChanged(Event event) throws IOException {
        Tab tab = (Tab) event.getSource();
        Node node =tab.getContent();
        if(node == null){
            String fxmlPath = tab.getId();
            if(StringUtils.isNotEmpty(fxmlPath)) {
                node = FXMLLoader.load(getClass().getResource(fxmlPath));
                tab.setContent(node);
                tab.setOnSelectionChanged(null);//只加载一次数据，加载完成后，监听可以取消
            }
        }
    }

    @Override
    public void close() {

    }
}
